/**
 * Created by Administrator on 2018/1/13.
 */
/**
 * Created by Administrator on 2017/12/2.
 */
define(function(require, exports, module) {
    var $=require('zepto');
    api=require('api');
    cn=require('conment');
    cook=require('cookie');
    module.exports = {
        int:{
            is:false,
            isApprove:false,
        },
        isLogin:function () {
            const _this=this;
            cn.Ajax(api.isLogin,{
            },function(d){
                if(d.flag==1){
                    $('.loginYes').show();
                    // $('#loginNot').hide()
                    $('.head-name').text(d.nickname)
                    sessionStorage.setItem('testKey',true);
                    sessionStorage.setItem('nickName',d.nickname);
                    _this.int.is=true;
                    if(d.name!=''&&d.name!=null){
                        _this.int.isApprove=true;
                        sessionStorage.setItem('realityName',true);
                        $('#isName').text('已认证');
                    }else {
                        sessionStorage.setItem('realityName',false);
                        $('#setting_name').attr('href','/view/real_name.html')
                    }
                    _this.finance()
                }else{
                    // $('#loginYes').hide();
                    $('.loginNot').show();
                    sessionStorage.removeItem('testKey',true);
                    _this.int.is=false;
                }
            },'post')
        },
        finance:function () {
            const _this=this;
            cn.Ajax(api.finance,{
            },function(d){
                if(d.flag==1){
                    $('.txt-id').text(parseFloat(d.available).toFixed(2));
                    sessionStorage.setItem('money',d.available);
                }
            },'post')
        },
        loginOut:function () {
            const _this=this;
            cn.Ajax(api.logout,{
            },function(d){
                if(d.flag==1){
                    sessionStorage.removeItem('testKey');
                    cn.alert(d.message);
                    setTimeout(function () {
                        window.location.href='/view/user.html'
                    },1000);
                }
            },'post')
        },
        bank_list:function () {
            const _this=this;
            cn.Ajax(api.bankcardList,{
            },function(d){
                if(d.flag==1){
                    if(d.list.length>0){
                       $('#isbank').text('已绑定')
                    }else{
                        $("#bind_bank").attr('href','/view/bind_bank.html')
                    }
                }
            },'post')
        },
        setting:function () {
            const _this=this;
            _this.bank_list();
            _this.isLogin();
            $('#loginOut').on('click',function () {
                _this.loginOut()
            });
        },
        init:function () {
            const _this=this;
            _this.isLogin();
            $('.islogin').on('click',function () {
                if(!_this.int.is){
                    window.location.href='/view/login.html'
                }else {
                    window.location.href='/view/'+$(this).data('href')+'.html'
                }
            });

            $('.ispay').on('click',function () {
                if(!_this.int.is){
                    window.location.href='/view/login.html'
                }else {
                   if(_this.int.isApprove){
                       window.location.href='/view/'+$(this).data('href')+'.html'
                   }else{
                       cn.modelDialog({
                           msg:'请先实名认证',
                           btnValue:'取消',
                           btn:[{
                               txt:'确定',
                               callBack:function(){
                                   window.location.href='/view/real_name.html'
                               }
                           }]
                       });
                   }
                }
            })
        }

    }
});